#ifndef CONFIGFILE_H
#define CONFIGFILE_H

#include <defs/export.h>
#include <defs/global.h>

#include <Core/config/config.h>
#include <QtCore>

namespace Opl
{
    namespace Core
    {

        O_PRIVATE_DECLARE(ConfigFile);

        /*!
         Class for read and write config file.
         File must be in json format
         example config:
         {
             "Section":{
                 "Key":"value",
                 "Key2":9,
                 "Key2":false
             },
             "Section1":{
                 "Key":"value"
             }
         }
         */
        class CORE_EXPORT ConfigFile : public virtual IConfig
        {
                Q_OBJECT
            public:

                /*!
                 Find file in search path
                 return full path to first found ot empty
                 \param filepath path to config file
                 */
                ConfigFile(const QString& filepath = QString());
                virtual ~ConfigFile();

                void setFileName(const QString& fn);
                QString fileName()const;

                /*!
                 Load config from file
                 */
                virtual bool load();
                virtual bool load(const QString& filepath);

                /*!
                 Save config to file
                 */
                virtual bool save();
                virtual bool save(const QString& filepath);

                /*!
                 Read value from configmap
                 */
                virtual QVariant value(const QString& section, const QString& key, const QVariant& def);

                virtual QVariantList values(const QString& path);
                virtual QVariant value(const QString& path, const QVariant& def = QVariant());

                /*!
                 Store value to config map
                 */
                virtual void setValue(const QString& section, const QString& key, const QVariant& val);
            private:
                Q_DISABLE_COPY(ConfigFile)
                O_PRIVATE_DECLARE_MEMBER(ConfigFile);
        };

    }
}

#endif // CONFIGFILE_H

